package purchase.wf;

import java.util.Collection;
import java.util.Iterator;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.jbpm.taskmgmt.exe.TaskMgmtInstance;


public class ModifyJoinNodeAction implements ActionHandler {

	public void execute(ExecutionContext executionContext) throws Exception {

		TaskMgmtInstance taskMgmtInstance = executionContext.getTaskMgmtInstance();
		Token rootToken = executionContext.getProcessInstance().getRootToken();
		
		//get child token list
		Collection childTokenList = rootToken.getChildren().values();
		
		for (Iterator ite = childTokenList.iterator(); ite.hasNext();) {
			Token childToken = (Token)ite.next();
			Collection unFinishedTasks = taskMgmtInstance.getUnfinishedTasks(childToken);
			
			for (Iterator _ite = unFinishedTasks.iterator(); _ite.hasNext();) {
				TaskInstance unFinishedTask = (TaskInstance)_ite.next();
				//cancel
				unFinishedTask.cancel();
			}
			
		}
		
	}

}
